package day9;

import static day9.MyRunnable5.lock;

class test2 extends Thread {

    public test2 (String name) {
        super(name);
    }

    static int count = 80;
    @Override
    public void run() {
        while (true) {

            if (count >= 0){
                try {
                    lock.lock();
                    Thread.sleep(50);
                    System.out.println(lock + Thread.currentThread().getName() + "还剩" + (count--) + "个座");
                } catch (Exception e) {
                    e.printStackTrace();
                } finally {
                  lock.unlock();
                }
            } else {
                Runtime.getRuntime().exit(0);
            }
        }
    }
}

public class Demo9 {
    public static void main(String[] args) {
        Thread t = new test2("前门");
        Thread t2 = new test2("后门");
        t.start();
        t2.start();
    }
}
